<?php
namespace admin\action;

use herosphp\bean\Beans;
use herosphp\exception\UnSupportedOperationException;
use herosphp\http\HttpRequest;
use herosphp\utils\AjaxResult;

/**
 * payway action(支付通道)
 * @package admin\action
 * @author yangjian<yangjian102621@gmail.com>
 */
class PaywayAction extends CommonAction {

    protected $serviceBean = 'payment.payway.service';
    protected $actionTitle = '支付通道';

    //数据列表页面
    public function index( HttpRequest $request ) {
        parent::index($request);
        $this->setView('payment/payway_index');
        $this->assign('breadcrumb', array('支付管理', '支付通道'));
    }

    //数据添加页面
    public function add(HttpRequest $request) {
        throw new UnSupportedOperationException("暂时不支持该操作.");
    }

    //数据编辑页面
    public function edit(HttpRequest $request) {
        $id = $request->getParameter('id', 'intval');
        if ( $id <= 0 ) {
            AjaxResult::ajaxResult(AjaxResult::OP_FAILURE, self::NO_RECORDS);
        }
        $service = Beans::get($this->getServiceBean());
        $item = $service->getItem($id);
        if ( empty($item) ) {
            AjaxResult::ajaxResult(AjaxResult::OP_FAILURE, self::NO_RECORDS);
        }
        AjaxResult::ajaxResult(AjaxResult::OP_SUCCESS, null, $item);
    }

    //插入数据操作
    public function insert(HttpRequest $request) {

        $data = $request->getParameter('data');
        parent::__insert($data);
    }
    //更新数据操作
    public function update(HttpRequest $request) {

        $data = $request->getParameter('data');
        $id = $request->getParameter('id', 'trim');
        parent::__update($data, $id);

    }
}
